home *** CD-ROM | disk | FTP | other *** search
- unit DMSQLCriteria;
-
- {
- Other criteria you can define;
- - TDMSQLCheckBox, for Boolean fields (which must also be added to the
- set of supported field types).
- - TDMSQLComboBox (similar to TMDSQLListBox).
- - TDMSQLLookupListBox (a TDMSQLListBox bound to a DataSet).
- - TDMSQLLookupComboBox (a TDMSQLComboBox bound to a DataSet).
- - TDMSQLRadioGroup (similar to TDMSQLListBox).
- - TDMSQLLookupRadioGroup (a TDMSQLRadioGroup bound to a DataSet).
-
- Possible support components:
- - A ComboBox linked to a criterion, used to set its SQLOperator property.
- - A RadioGroup or ListBox with the same function.
- - A ComboBox, or ListBox etc. to set the value of the DataField property.
- }
-
- interface
-
- uses
- Classes, StdCtrls, DB, DMSQLBase;
-
- type
- // An Edit box criterion.
- TDMSQLEdit = class(TEdit, IDMSQLCriterion, IDMSQLCriterionData)
- private
- FCriterion: TDMSQLSingleCriterion;
- function GetSQLValue: Variant;
- procedure ClearSQL;
- protected
- procedure Notification(AComponent: TComponent; Operation: TOperation); override;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- published
- property Criterion: TDMSQLSingleCriterion read FCriterion write FCriterion implements IDMSQLCriterion;
- end;
-
- // A ListBox multiple criterion.
- TDMSQLListBox = class(TListBox, IDMSQLCriterion, IDMSQLCriterionData)
- private
- FCriterion: TDMSQLMultipleCriterion;
- function GetSQLValue: Variant;
- procedure ClearSQL;
- protected
- procedure Notification(AComponent: TComponent; Operation: TOperation); override;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- published
- property Criterion: TDMSQLMultipleCriterion read FCriterion write FCriterion implements IDMSQLCriterion;
- end;
-
- implementation
-
- uses
- SysUtils, DMSQLUtils;
-
- { TDMSQLEdit }
-
- constructor TDMSQLEdit.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- FCriterion := TDMSQLSingleCriterion.Create(Self);
- end;
-
- destructor TDMSQLEdit.Destroy;
- begin
- FCriterion.Free;
- inherited;
- end;
-
- function TDMSQLEdit.GetSQLValue: Variant;
- begin
- Result := SQLStringToVariant(Text);
- end;
-
- procedure TDMSQLEdit.Notification(AComponent: TComponent; Operation: TOperation);
- begin
- inherited;
- FCriterion.CustomNotification(Acomponent, Operation);
- end;
-
- procedure TDMSQLEdit.ClearSQL;
- begin
- Clear;
- end;
-
- { TDMSQLListBox }
-
- constructor TDMSQLListBox.Create(AOwner: TComponent);
- begin
- inherited;
- FCriterion := TDMSQLMultipleCriterion.Create(Self);
- end;
-
- destructor TDMSQLListBox.Destroy;
- begin
- FCriterion.Free;
- inherited;
- end;
-
- function TDMSQLListBox.GetSQLValue: Variant;
- var
- VarIndex: Integer;
- g: Integer;
- begin
- if not MultiSelect then begin
- Result := VarArrayCreate([1, 1], varVariant);
- // Single selection: return a single value.
- if ItemIndex < 0 then
- Result[1] := SQLStringToVariant('')
- else
- Result[1] := SQLStringToVariant(Items[ItemIndex]);
- end
- else begin
- // Multiple selection: return an array.
- Result := VarArrayCreate([1, SelCount], varVariant);
- VarIndex := 1;
- for g := 0 to Pred(Items.Count) do
- if Selected[g] then begin
- Result[VarIndex] := SQLStringToVariant(Items[g]);
- Inc(VarIndex);
- end;
- end;
- end;
-
- procedure TDMSQLListBox.Notification(AComponent: TComponent; Operation: TOperation);
- begin
- inherited;
- FCriterion.CustomNotification(Acomponent, Operation);
- end;
-
- procedure TDMSQLListBox.ClearSQL;
- var
- g: Integer;
- begin
- if MultiSelect then begin
- for g := 0 to Pred(Items.Count) do
- if Selected[g] then
- Selected[g] := False;
- end
- else
- ItemIndex := -1;
- end;
-
- end.
-